package ru.compscicenter.databases.zaikina.common.commands;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import ru.compscicenter.databases.zaikina.common.commands.bodies.StringListBody;

import java.util.ArrayList;


public class StringListCommand extends SysCommand<ArrayList<String>, StringListBody> {
    public StringListCommand(Integer type, StringListBody body, Integer param) {
        super(type, body, param);
    }

    public StringListCommand(Integer type, ArrayList<String> body, Integer param) {
        super(type, body, param);
    }

    public static StringListCommand parse(String jsonStr) {
        JSONObject obj = (JSONObject) JSONValue.parse(jsonStr);
        if (SysCommandType.isStringListCommand(SysCommand.parseType(obj))) {
            Integer type = Integer.parseInt(obj.get("type").toString());
            Integer param = Integer.parseInt(obj.get("param").toString());
            StringListBody body = new StringListBody();
            body.getFromJsonString(obj.get("body").toString());
            return new StringListCommand(type, body, param);
        }
        return null;
    }
}
